package org.zxp.image;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * @program: effectiveJava
 * @description:
 * @author: X-Pacific zhang
 * @create: 2020-08-24 15:41
 **/
public class Test {
    public static void main(String[] args) throws Exception {
        OfficialSeal_1();//公章1
        OfficialSeal_3();//公章2

        PrivateSeal_1();//私章1
    }

    public static void OfficialSeal_1() throws Exception {
        Seal.builder()
                .size(200)
                .borderCircle(SealCircle.builder().line(4).width(95).height(95).build())
                .mainFont(SealFont.builder().text("新希望产融平台").family("宋体").size(22).space(22.0).margin(4).build())
                .centerFont(SealFont.builder().text("★").size(60).build())
                .titleFont(SealFont.builder().text("电子签章").size(16).space(8.0).margin(54).build())
                .build()
                .draw("D:/222/1.png");
    }

    public static void OfficialSeal_2() throws Exception {
        Seal.builder()
                .size(300)
                .borderCircle(SealCircle.builder().line(5).width(140).height(140).build())
                .mainFont(SealFont.builder().text("新希望产融平台").size(35).space(35.0).margin(10).build())
                .centerFont(SealFont.builder().text("★").size(100).build())
                .titleFont(SealFont.builder().text("电子签章").size(22).space(10.0).margin(68).build())
                .build()
                .draw("D:/222/2.png");
    }

    public static void OfficialSeal_3() throws Exception {
        Seal.builder()
                .size(300)
                .borderCircle(SealCircle.builder().line(3).width(144).height(100).build())
                .borderInnerCircle(SealCircle.builder().line(1).width(140).height(96).build())
                .mainFont(SealFont.builder().text("新希望产融平台").size(25).space(12.0).margin(10).build())
                .centerFont(SealFont.builder().text("NO.0876").size(20).build())
                .titleFont(SealFont.builder().text("电子合同专用章").size(20).space(9.0).margin(64).build())
                .build()
                .draw("D:/222/3.png");
    }

    public static void PrivateSeal_1() throws Exception {
        Seal.builder()
                .size(300)
                .borderSquare(16)
                .mainFont(SealFont.builder().text("猪八戒印").size(120).build())
                .build()
                .draw("D:/222/4.png");
    }

    public static void PrivateSeal_2() throws Exception {
        Seal.builder()
                .size(300)
                .borderSquare(16)
                .mainFont(SealFont.builder().text("猪八戒").size(120).build())
                .build()
                .draw("D:/222/5.png");
    }


    public static String graphicsGeneration() throws Exception {
        // 实际数据行数+标题+备注
        int imageWidth = 490;
        int imageHeight = 130;

        BufferedImage image = new BufferedImage(imageWidth, imageHeight,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = (Graphics2D) image.getGraphics();
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, imageWidth, imageHeight);

        // ---------- 增加下面的代码使得背景透明 -----------------
        // image =
        // g2d.getDeviceConfiguration().createCompatibleImage(imageWidth,
        // imageHeight, Transparency.TRANSLUCENT);
        // g2d.dispose();
        // g2d = image.createGraphics();
        // ---------- 背景透明代码结束 -----------------

        g2d.setColor(new Color(220, 240, 240));
        g2d.setStroke(new BasicStroke(3.0f));
        // 画横线
        g2d.setColor(Color.red);

        g2d.drawLine(10, 10, imageWidth - 10, 10);
        g2d.drawLine(10, imageHeight - 10, imageWidth - 10, imageHeight - 10);
        // 画竖线
        g2d.setColor(Color.red);
        g2d.drawLine(10, 10, 10, imageHeight - 10);
        g2d.drawLine(imageWidth - 10, 10, imageWidth - 10, imageHeight - 10);

        // 设置字体
        Font font = new Font("华文楷体", Font.BOLD, 25);
        g2d.setFont(font);
        // 写入内容
        g2d.setColor(Color.black);
        font = new Font("华文楷体", Font.BOLD, 25);
        g2d.setFont(font);
        g2d.drawString("人员：李某某", 12, 45);
        g2d.drawString("部门：综合业务处", 12, 100);

        g2d.drawString("下载次数：3次", 270, 45);
        g2d.drawString("时间：2018-10-15", 270, 100);

        String path = "D:/1.jpg";
        ImageIO.write(image, "jpg", new File(path));
        return path;
    }
}
